/*
 * Function test of qtsm_lib_api using glib framework
 *
 * Copyright (c) Huawei Technologies Co., Ltd. 2022. All Rights Reserved.
 * SPDX-License-Identifier: Apache-2.0.
 */
#include "gtest_qtsm_lib_comm.h"

static void open_qtsm_dev(const void *qtsm_dev_fd)
{
    *(int *)qtsm_dev_fd = qtsm_lib_init();
    g_assert_cmpint(*(int *)qtsm_dev_fd, >, 0);
}

static void close_qtsm_dev(const void *qtsm_dev_fd)
{
    qtsm_lib_exit(*(int *)qtsm_dev_fd);
}

int main(int argc, char *argv[])
{
    int qtsm_dev_fd = 0;
    g_test_init(&argc, &argv, NULL);

    g_test_add_data_func("/libqtsm/init_qtsm_dev", &qtsm_dev_fd, open_qtsm_dev);

    /* Single function test */
    g_test_add_data_func("/libqtsm/describe_pcr", &qtsm_dev_fd, gtest_qtsm_describe_pcr);
    g_test_add_data_func("/libqtsm/extend_pcr", &qtsm_dev_fd, gtest_qtsm_extend_pcr);
    g_test_add_data_func("/libqtsm/lock_pcr", &qtsm_dev_fd, gtest_qtsm_lock_pcr);
    g_test_add_data_func("/libqtsm/lock_pcrs", &qtsm_dev_fd, gtest_qtsm_lock_pcrs);
    g_test_add_data_func("/libqtsm/extend_locked_pcr", &qtsm_dev_fd, gtest_qtsm_extend_pcr);
    g_test_add_data_func("/libqtsm/describe_qtsm", &qtsm_dev_fd, gtest_qtsm_get_describe);
    g_test_add_data_func("/libqtsm/attestation", &qtsm_dev_fd, gtest_qtsm_get_attestation);

    g_test_add_data_func("/libqtsm/destroy_qtsm_dev", &qtsm_dev_fd, close_qtsm_dev);

    return g_test_run();
}
